<?php

namespace app\controller;

use app\traits\ControllerTrait;

class AudioFrequency extends ControllerTrait
{
    public function Index()
    {
    }

    /**
     * 审核通过列表
     */
    public function ApprovedList()
    {
        $list = app('audioFrequencyModel')
            ::where('audit', 1)
            ->field(["uid", "name", "cover_url", "singer", "audio_url", "remark", "audit"])
            ->order('id', 'asc')
            ->select();
        $this->success($list, '审核通过列表');
    }

    public function IndividuationList()
    {
        $list = app('audioFrequencyModel')
            ::where('audit', 1)
            ->field(["uid", "name", "cover_url", "audio_url", "remark", "audit"])
            ->order('id', 'asc')
            ->select();
        $this->success($list, '审核通过列表');
    }

    /**
     * 审核未通过列表
     */
    public function auditFailedList()
    {
        $list = app('audioFrequencyModel')
            ->field(["uid", "name", "cover_url", "audio_url", "remark", "audit", 'create_time', 'update_time'])
            ->order('id', 'asc')
            ->select();
        $this->success($list, '审核未通过列表');
    }

    /**
     * 创建音频资源
     */
    public function createAudioFrequency()
    {
        $param = $this->request->param();
        $rule = [
            "name|音频名称" => "require",
            "audio_url|音频地址" => "require",
            "cover_url|封面地址" => "",
            "remark|音频备注信息" => "",
        ];
        $this->validate($param, $rule);
        $user = app('audioFrequencyModel');
        $uid = create_guid();
        $user->save([
            'uid' => $uid,
            'name' => $param['name'],
            'cover_url' => $param['cover_url'],
            'audio_url' => isset($param['audio_url']) ? $param['audio_url'] : '',
            'remark' => isset($param['remark']) ? $param['remark'] : ''
        ]);
        $this->success($user, '操作成功');
    }

    /**
     * 审核歌曲
     */
    public function auditAudioFrequency()
    {
        $param = $this->request->param();
        $rule = [
            "uid|音频 uid" => "require",
            "audit|审核意见" => "require",
        ];
        $this->validate($param, $rule);
        $audioFrequency = app('audioFrequencyModel')
            ::where(['uid' => $param['uid']])
            ->find();

        $audioFrequency->audit = $param['audit'];
        $audioFrequency->force()->save();

        $this->success($audioFrequency, '操作成功');
    }
}